﻿@{
    ViewBag.Title = "UpdateInfo";
}

@section scripts
{
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />       
    <link rel="stylesheet" href="../Scripts/kindeditor-4.1.10/themes/default/default.css" />
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/kindeditor-all.js"></script>
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>    
}

<form id="form1" method="post">
            @Html.Partial("~/Views/Modular/Toolbars.cshtml")
        <div name="Base" title="升级公告" style="height:100%;overflow:hidden;margin-top:15px;margin-left:20px">
            <table>
                <tr>
                    <td width="80px" height ="50px" align="right">
                        日期：</td>
                    <td width="250px" height ="50px">
                        <input id="FCreateTime" name="FCreateTime" enabled="false" class="mini-datepicker " format="yyyy-MM-dd" style="width:200px;" tabindex="1"/>
                    </td>
                    <td width="80px" height ="50px" align="right">
                        类型：</td>
                    <td width="250px" height ="50px">
                        <input id="FType" name="FType" class="mini-combobox" style="width:200px;" showNullItem="false" 
                            allowInput="false" align="left" value ="1" data ="comType" tabindex="2"/> 
                    </td>
                </tr>
                 <tr>
                    <td width="80px" height ="50px" align="right">
                        标题：</td>
                    <td width="250px" height ="50px" colspan="3">
                        <input id="FTitle" name="FTitle" class="mini-textbox " style="width:603px;" tabindex="3"/>
                    </td>
                </tr>
               <tr>
                    <td width="80px" height ="50px" align="right">
                        内容：</td>
                    <td width="250px" colspan="3">
                        <textarea id="FContent" name="FContent" style="width:700px;height:350px;visibility:hidden;" tabindex="4"></textarea>
                    </td>
                </tr>
            </table>
            <br />
        </div>
    <input name="FItemID" class="mini-hidden" />
</form>

<script>
    var comType = [{ "id": "1", "text": "后台web更新" },
                      { "id": "2", "text": "PC收银端更新" },
                      { "id": "3", "text": "手机微信更新" }];
    var editor2;
    mini.parse();

    function FormShown() {
    }

    $(function () {
        var nowDate = new Date();
        mini.getbyName("FCreateTime").setValue(nowDate);

        KindEditor.ready(function (K) {
            editor2 = K.create('textarea[name="FContent"]', {
                uploadJson: '../asp.net/upload_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true' + '&iseDitor=true',
                fileManagerJson: '../asp.net/file_manager_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID(),
                afterBlur: function () { this.sync(); },
                allowFileManager: true
            });
        });
    });

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            NewInfo();
        }
        else {
            $.post("GetInfo", { json: "[{'FItemID':'" + data.FItemID + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                var htmlstr = decodeURIComponent(mdata.data[0].FContent);
                editor2.insertHtml(htmlstr);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        editor2.insertHtml("");
    }

    //保存资料
    function SaveInfo() {
        var FContent = encodeURIComponent($("#FContent").val());
        if (FContent == '') {
            mini.alert("更新说明不能为空");
            return;
        }
        if (mini.getbyName('FTitle').getValue() == '') {
            mini.alert("标题不能为空");
            return;
        }
        if (mini.getbyName('FTitle').getValue().length>200) {
            mini.alert("标题字符数不能大于200");
            return;
        }
        mini.getbyName("SaveInfo").setEnabled(false);
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        data.FContent = FContent;

        var json = mini.encode(data);
        $.post("SaveInfo", { json: json}, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }

</script>